package com.fand.platform.common.controller;

import lombok.extern.slf4j.Slf4j;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * @author yaoHT
 */
@Controller
@Slf4j
public class ErrorPageController {
	@RequestMapping(value = { "/error/404.html" })
	public String error404(final Exception ex, final Model model) {
		this.setModel(ex, model);

		return "error/404";
	}

	@RequestMapping(value = { "/error/500.html" })
	public String error500(final Exception ex, final Model model) {
		this.setModel(ex, model);

		return "error/500";
	}

	private void setModel(final Exception ex, final Model model) {
		model.addAttribute("message", ex.getMessage());

		if (ex != null) {
			ex.printStackTrace();
		}

		if (ErrorPageController.log.isErrorEnabled()) {
			ErrorPageController.log.error(ex.getMessage(), ex);
		}
	}
}
